package com.excesys.exsecs.access.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.excesys.exsecs.access.dto.AccessSubareaDTO;
import com.excesys.exsecs.access.vo.AccessSubareaVO;
import com.excesys.exsecs.common.data.datascope.ExsecsBaseMapper;
import com.excesys.exsecs.access.entity.AccessSubarea;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AccessSubareaMapper extends ExsecsBaseMapper<AccessSubarea> {

    /**
     * 按条件联表查询,使用 Wrapper自定义SQL
     */
    @Select("SELECT bama.*,bamb.buildings_cn AS buildings_name,bamf.floor_cn AS floor_name "
            + "FROM access_subarea bama LEFT JOIN access_buildings bamb ON " + "bamb.buildings_id = bama.subarea_jzbm "
            + "LEFT JOIN access_floor bamf ON bama.subarea_lc = bamf.floor_code " + "${ew.customSqlSegment}  ")
    IPage<AccessSubareaVO> getBamSSubareaVosPage(IPage<Object> page,
                                               @Param(Constants.WRAPPER) QueryWrapper<AccessSubareaDTO> query);

    /**
     * 按条件联表查询,使用 Wrapper自定义SQL
     */
    @Select("SELECT bama.*,bamb.buildings_cn AS buildings_name,bamf.floor_cn AS floor_name "
            + "FROM access_subarea bama LEFT JOIN access_buildings bamb ON " + "bamb.buildings_id = bama.subarea_jzbm "
            + "LEFT JOIN access_floor bamf ON bama.subarea_lc = bamf.floor_code " + "${ew.customSqlSegment}  ")
    List<AccessSubareaVO> getBamSSubareaVos(@Param(Constants.WRAPPER) QueryWrapper<AccessSubareaDTO> query);

    List<AccessSubarea> queryBydCode(@Param("queryBydCode") String queryBydCode);

    IPage<AccessSubareaVO> selectBamSSubareaByPages(IPage<Object> page,
                                                  @Param(Constants.WRAPPER) QueryWrapper<AccessSubareaDTO> query);

    List<AccessSubareaVO> selectBamSSubareaVos(@Param(Constants.WRAPPER) QueryWrapper<AccessSubareaDTO> query);

    //List<AccessSubareaVO> selectBamSSubareaWithFVVos(@Param(Constants.WRAPPER) QueryWrapper<AccessSubareaDTO> query);

    List<AccessSubareaVO> selectAll();

    AccessSubareaVO selectByPrimaryKey(String id);

    AccessSubareaVO selectByCode(String subareacode);

}